package com.cloudcreativity.blyg.ui.goods;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.KeyEvent;

import com.cloudcreativity.blyg.R;
import com.cloudcreativity.blyg.base.BaseActivity;
import com.cloudcreativity.blyg.databinding.ActivityGoodsListBinding;
import com.cloudcreativity.blyg.utils.ScanGunHelper;

public class GoodsListActivity extends BaseActivity {

    private GoodsListModel model;
    private ScanGunHelper scanGunHelper;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityGoodsListBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_goods_list);
        model = new GoodsListModel(this, binding, this);
        binding.setModel(model);
        scanGunHelper = new ScanGunHelper(new ScanGunHelper.OnScanValueListener() {
            @Override
            public void onScanValue(String value) {
                if(!TextUtils.isEmpty(value) && value.length()>=13){
                    model.onScan(value);
                }
            }
        });
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        scanGunHelper.analysisKeyEvent(event);
        return true;
    }
}
